package com.xiaotao.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Configuration

public class RabbitMqConfig {
    @Bean
    public CustomExchange customExchange() {
        Map<String, Object> map = new HashMap<>();
        map.put("x-delayed-type", "topic");
        return new CustomExchange("userCoupon", "x-delayed-message", true, false, map);
    }

    @Bean
    public Queue userCouponQueue() {
        return new Queue("userCouponQueue");
    }

    @Bean
    public Binding userCouponQueueToCustomExchange() {
        return BindingBuilder.bind(userCouponQueue()).to(customExchange()).with("checkCoupon").noargs();
    }
}
